#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> tree(n);
	for(int i=0;i<n;i++){
		cin>>tree[i];
	}
	
	int ans = 0; 
	queue<int> nodes;
	nodes.push(0);
	while(!nodes.empty()){
		int front = nodes.front();
		nodes.pop();
		int l = front*2+1;
		int r = front*2+2;
		if((tree[l]==-1 || l>=n) && (tree[r]==-1 || r>=n) && front%2==1){
			ans += tree[front];
			continue;
		}
		if(tree[l]!=-1 && l<n){
			nodes.push(l);
		}
		if(tree[r]!=-1 && r<n){
			nodes.push(r);
		}
	}
	
	cout<<ans<<endl;
    return 0;
} 
